package cc.douquan.com.doutu.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Environment;
import android.view.WindowManager;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;

import java.io.File;
import java.util.Random;

import cc.douquan.com.doutu.Constants;
import cc.douquan.com.doutu.MyApplication;
import cc.douquan.com.doutu.R;

/**
 * Created by feq on 2016/11/17.
 */

public class GlideUtis {
    public static void setImg(String imgUrl, ImageView view) {
        Glide.with(MyApplication.getContext()).
                load(imgUrl).
                placeholder(R.mipmap.loading).
                into(view);
    }

    public static void downImg(final Context context, final String imgUrl, final int type) {
        Glide.with(MyApplication.getContext()).load(imgUrl)
                .asBitmap()
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                        if (type == Constants.SAVE_YTPE) {
                            BitmapUtil.saveBitmap(bitmap, Environment.getExternalStorageDirectory()
                                    + File.separator + "shendou", Md5Utils.md5(imgUrl) + ".jpg", true);
                        } else {
                            ShareUtils.shareGirl(bitmap, context);
                        }
//                        return bitmap
                    }
                });
    }

}
